<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            height: 100%;
        }
        .parent{
            height: 400px;
            width: 400px;
            background-color: pink;
            position: relative;
        }
        .son{
            height: 200px;
            width: 200px;
            background-color: purple;
            position: absolute;
            left: 50%;
            top: 50%;

            /* 
                由于translate中如果给了百分比，则是相对于自身宽高的，所以我们可以利用这一点让子盒子跑到中间去 
            */
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="son"></div>
    </div>
</body>
</html>